package com.zt.bigdata.vertx

import com.typesafe.scalalogging.LazyLogging
import io.vertx.core.http.HttpServerResponse

/**
  *
  */
class ResponseContent extends LazyLogging {

  def returnContent(response: HttpServerResponse, res: String): Unit = {
    logger.trace("Response: \r\n" + res)
    response.setStatusCode(200).putHeader("Content-Type", "application/json; charset=utf-8")
      .putHeader("Cache-Control", "no-cache")
      .putHeader("Access-Control-Allow-Origin", ResponseContent.ALLOW_ORIGIN)
      .putHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
      .putHeader("Access-Control-Allow-Headers", "Content-Type, X-Requested-With, X-client," + ResponseContent.FLAG_AUTHORIZATION + "," + ResponseContent.FLAG_PROXY)
      .end(res);
  }
}

object ResponseContent {
  val FLAG_AUTHORIZATION = "X-Auth"
  val FLAG_PROXY = "X-Forwarded-For"
  val ALLOW_ORIGIN = "X-Forwarded-For"
}
